package com.baizhi.wzd.service;

import com.baizhi.wzd.dao.AdminDao;
import com.baizhi.wzd.dao.UserMapper;
import com.baizhi.wzd.entity.User;
import com.baizhi.wzd.entity.UserExample;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Transactional
public class UserServiceImpl implements UserService{
    @Autowired
    private UserMapper userMapper;
    //分页
    @Override
    public Map<String, Object> queryAllPage(int page,int pageSize) {
        Map<String,Object> map = new HashMap<String,Object>();
        UserExample userExample = new UserExample();
        RowBounds rowBounds = new RowBounds((page - 1) * pageSize, pageSize);
        List<User> users = userMapper.selectByExampleAndRowBounds(userExample,rowBounds);
        int totalCount = userMapper.selectCount(null);
        map.put("total",totalCount);
        map.put("page",page);
        map.put("rows",users);
        return map;
    }

    @Override
    public Map<String,String> modify(User user) {
        Map<String,String> map = new HashMap<String,String>();
        userMapper.updateByPrimaryKeySelective(user);
        if(user.getStatus().equals("1")){
            map.put("message","操作成功");
            map.put("status","200");
            return map;
        }else {
            map.put("message","操作失败");
            map.put("status","400");
            return map;
        }
    }

}
